<template name="newAdminNetworkCapabilitiesTableCapabilityRow">
{{!-- expects argument:
  capInfo: Object containing:
                 introducer: Identity object
                 grainTitle: String
                    appIcon: String
         grainOwnerIdentity: Identity object
                    created: Date
                    revoked: Boolean
  callbacks: Object containing:
    onRevokeCap: Function to call when the Revoke button is clicked.
--}}
<div class="capability-row" role="row">
  <div class="grant-by" role="gridcell">
    {{#if capInfo.introducer.identity}}
      {{> identityCard capInfo.introducer.identity }}
    {{else}}
      {{#if capInfo.introducer.account}}
        {{#linkTo route="newAdminUserDetails" data=capInfo.introducer.account}}
          {{!-- to access things in previous context from within linkTo, we must reach up two data
                contexts --}}
          Admin account {{ ../../capInfo.introducer.account.userId }}
        {{/linkTo}}
      {{else}}
        Unknown granter
      {{/if}}
    {{/if}}
  </div>
  <div class="grant-to" role="gridcell">
    {{#if capInfo.ownerInfo.grain}}
      <div class="grain-context">
        <div class="grain-details">
          <div class="app-icon" style="background-image: url('{{capInfo.ownerInfo.grain.appIcon}}')"></div>
          {{capInfo.ownerInfo.grain.title}}
        </div>
        {{#if capInfo.ownerInfo.grain.grainOwnerIdentity}}
          {{> identityCard capInfo.ownerInfo.grain.grainOwnerIdentity }}
        {{/if}}
      </div>
    {{else}}
      {{#if capInfo.ownerInfo.webkey}}
        Anyone with the token
      {{else}}
        Unknown recipient
      {{/if}}
    {{/if}}
  </div>
  <div class="grant-time" role="gridcell">{{dateString capInfo.created}}</div>
  <div class="actions" role="gridcell">
    {{#if capInfo.revoked}}
      Revoked
    {{else}}
    <form class="standard-form">
      <button type="button">
        Revoke
      </button>
    </form>
    {{/if}}
  </div>
</div>
</template>

<template name="newAdminNetworkCapabilitiesTable">
{{!-- Takes arguments:
  caps: cursor with list of Object like those returned by capDetails
--}}
<div class="admin-caps-table" role="grid">
  <div class="thead" role="rowgroup">
    <div class="header-row" role="row">
      <div class="grant-by" role="columnheader">Granted by</div>
      <div class="grant-to" role="columnheader">Granted to</div>
      <div class="grant-time" role="columnheader">Time</div>
      <div class="actions" role="columnheader">Actions</div>
    </div>
  </div>
  <div class="tbody" role="rowgroup">
    {{#each cap in caps}}
      {{>newAdminNetworkCapabilitiesTableCapabilityRow capInfo=cap callbacks=callbacks }}
    {{else}}
    <div class="none-row" role="row">
      <div role="gridcell" colspan="4">No capabilities found.</div>
    </div>
    {{/each}}
  </div>
</div>
</template>

<template name="newAdminNetworkCapabilitiesSection">
{{!-- Takes arguments:
  caps: Cursor of a list of ApiTokens.
--}}

{{#if hasSuccess}}
  {{#focusingSuccessBox}}
    {{message}}
  {{/focusingSuccessBox}}
{{/if}}

{{#if hasError}}
  {{#focusingErrorBox}}
    {{message}}
  {{/focusingErrorBox}}
{{/if}}

<div class="admin-caps-filter">
  <div class="search-bar">
    <div class="icon icon-search"></div>
    <input type="text" name="search-string" value="{{ filterString }}"/>
  </div>
  <div class="filter-checkboxes">
    <div class="filter-checkboxes-label">Showing:</div>
    <ul>
      <li>
        <label>
          <input type="checkbox" name="active" checked="{{ activeChecked }}" />
          Active ({{ activeCount caps }})
        </label>
      </li>

      <li>
        <label>
          <input type="checkbox" name="revoked" checked="{{ revokedChecked }}" />
          Revoked ({{ revokedCount caps }})
        </label>
      </li>
    </ul>
  </div>
</div>

{{> newAdminNetworkCapabilitiesTable caps=(filterCaps caps) callbacks=callbacks }}
</template>


<template name="newAdminNetworkCapabilities">
<h1>
  <ul class="admin-breadcrumbs">
    <li>{{#linkTo route="newAdminRoot"}}Admin{{/linkTo}}</li>
    <li>Network capabilities</li>
  </ul>
</h1>

<h2>Outbound network access</h2>
{{>newAdminNetworkCapabilitiesSection caps=ipNetworkCaps}}

<h2>TLS-encrypted outbound network access</h2>
{{>newAdminNetworkCapabilitiesSection caps=ipNetworkCapsTls}}

<h2>Inbound network access</h2>
{{>newAdminNetworkCapabilitiesSection caps=ipInterfaceCaps}}

</template>
